// 外观模式

package facade

import "fmt"

// 定义一个基础接口，外部不可见
type drawer interface {
	draw()
}

// 继承基础接口定义画圆
type circle struct {
	drawer
}

func (c *circle) draw() {
	fmt.Println("draw circle")
}

// 继承基础接口定义画矩形
type square struct {
	drawer
}

func (s *square) draw() {
	fmt.Println("draw square")
}

// 定义外观模型，将画圆和画矩形封装起来
type Facade struct {
	circleDrawer circle
	squareDrawer square
}

// 实现画圆的接口
func (f *Facade) DrawCircle() {
	if f.circleDrawer.drawer == nil {
		f.circleDrawer = circle{}
	}
	f.circleDrawer.draw()
}

// 实现画矩形的接口
func (f *Facade) DrawSquare() {
	if f.squareDrawer.drawer == nil {
		f.squareDrawer = square{}
	}
	f.squareDrawer.draw()
}

/*
func main() {
	facade := &Facade{}
	facade.DrawCircle()
	facade.DrawSquare()
}
*/
